package com.example.project.activity.jizhang;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.project.R;
import com.example.project.activity.mingxi.MainActivity;
import com.example.project.activity.tubiao.MonthChartActivity;
import com.example.project.activity.wode.WdActivity;
import com.example.project.adapter.RecordPagerAdapter;
import com.example.project.frag_record.IncomeFragment;
import com.example.project.frag_record.OutcomeFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class RecordActivity extends AppCompatActivity implements View.OnClickListener{
    private ImageView Ivjz,Ivbb,Ivzj,Ivwd;//下方跳转的控件
    private TextView tv_ls; //下方跳转的字体
    TabLayout tabLayout; //分页布局
    ViewPager viewPager; //引导页

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView( R.layout.activity_record);
        initView(); //实例化控件
        initPager(); //设置ViewPager加载页面
    }

    //实例化控件
    private void initView() {
        Ivjz = findViewById( R.id.Iv_jz );
        Ivjz.setOnClickListener( this );
        Ivbb = findViewById( R.id.Iv_bb );
        Ivbb.setOnClickListener( this );
        Ivzj = findViewById( R.id.Iv_zj );
        Ivzj.setOnClickListener( this );
        Ivwd = findViewById( R.id.Iv_wd );
        Ivwd.setOnClickListener( this );
        tv_ls= findViewById( R.id.tv_zj );

        tabLayout = findViewById( R.id.record_tabs);
        viewPager = findViewById( R.id.record_vp);
        //初始化下方跳转的控件颜色的改变
        Ivzj.setImageResource( R.drawable.jzb );
        tv_ls.setTextColor( Color.parseColor("#87CEFA") );
    }

    //设置ViewPager加载页面
    private void initPager() {
        //初始化ViewPager页面的集合
        List<Fragment> fragmentList = new ArrayList<>();
        //创建收入和支出页面，放置在Fragment当中
        OutcomeFragment outFrag = new OutcomeFragment(); //支出
        IncomeFragment inFrag = new IncomeFragment(); //收入
        fragmentList.add(outFrag);
        fragmentList.add(inFrag);
        //创建适配器
        RecordPagerAdapter pagerAdapter = new RecordPagerAdapter(getSupportFragmentManager(), fragmentList);
        //设置适配器
        viewPager.setAdapter(pagerAdapter);
        //将TabLayout和ViwePager进行关联
        tabLayout.setupWithViewPager(viewPager);
    }

    /* 点击事件*/
    public void onClick(View view) {
        Intent intent=null;
        switch (view.getId()) {
            case R.id.Iv_jz:
                intent=new Intent(this, MainActivity.class);
                startActivity( intent );
                break;
            case R.id.Iv_bb:
                intent=new Intent(this, MonthChartActivity.class);
                startActivity( intent );
                break;
            case R.id.Iv_wd:
                intent=new Intent(this, WdActivity.class);
                startActivity( intent );
                break;
        }
    }
}
